import { observable, action } from 'mobx';
import {WeaTableNew,WeaForm} from 'comsMobx';
const {TableStore} = WeaTableNew;
import { WeaLocaleProvider } from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;

/**
 * 项目列表通用store模板，适用于列表+高级搜索查询模式/
 */
export class ListStore{
    /** 列表store */
    @observable loading = false;
    dataKey = "";
   @observable tableTaskStore = new TableStore({dataHandle: (datas) => {  //任务列表
    datas.forEach((data) => {
      if (typeof(data.subListspan) == 'string') {
    data.subListspan = data.subListspan ? JSON.parse(data.subListspan) : undefined;
      }
    });
    return datas;
      }});
    @observable tableStore = new TableStore({dataHandle: (datas) => {  //任务列表
    datas.forEach((data) => {
        if (typeof(data.subListspan) == 'string') {
    data.subListspan = data.subListspan ? JSON.parse(data.subListspan) : undefined;
        }
    });
    return datas;
        }});
    @observable tableStoreDbInquire = new TableStore();
    @observable tableStoreMyAttent = new TableStore();
    @observable tableStoreLog = new TableStore();
    @observable tableStoreTask = new TableStore({dataHandle: (datas) => {  //任务列表
        datas.forEach((data) => {
          if (typeof(data.subListspan) == 'string') {
        data.subListspan = data.subListspan ? JSON.parse(data.subListspan) : undefined;
          }
        });
        return datas;
          }});

    /** 顶部查询store */
    @observable form = new WeaForm();
    @observable formB = new WeaForm();
    @observable condition = [];
    @observable formMyAttent = new WeaForm();
    @observable formSlide = new WeaForm();
    @observable showSearchAd = false;
    @observable topTab = [];//顶部Tab组件
     condition = [];
    constructor() {
        this.setLoading = this.setLoading.bind(this);
        this.setFormFields = this.setFormFields.bind(this);
        this.appendFormFields = this.appendFormFields.bind(this);
        this.clearFormFields = this.clearFormFields.bind(this);
        this.resetForm = this.resetForm.bind(this);
        this.resetTable = this.resetTable.bind(this);
        this.clearFormFields = this.clearFormFields.bind(this);
        this.setShowSearchAd = this.setShowSearchAd.bind(this);
    }
     //刷新列表
     reLoad = () => {
        this.tableStoreTask.getDatas(this.tableStoreTask.dataKey, this.tableStoreTask.current, this.tableStoreTask.pageSize, this.tableStoreTask.sortParams)
    }

    @action
    setLoading(bool = false){
        this.loading = bool;
    }

    setFormFields(value){
        this.form.updateFields(value, false);    //true代表完全覆盖方式更新条件值
    }

    appendFormFields(value){
        this.form.updateFields(value, false);
    }

    clearFormFields(){
        this.form.resetForm();      //清除查询条件值
    }

    resetForm(){
        this.form = new WeaForm();
    }

    resetTable(needNew=false){
        if(needNew)
            this.tableStore = new TableStore();
        else
            this.tableStore.tableUpdate({datas: []});
    }
    setShowSearchAd(bool) {
        this.showSearchAd = bool;
    }

}
